package org.bite.lesson05;

public class Demo_501 {
    public static void main(String[] args) throws InterruptedException{
        Counter501 counter501 = new Counter501();

        Thread t1 = new Thread(()->{
            for(int i = 0; i < 5000; i++){
                counter501.increase();
            }
        });
        Thread t2 = new Thread(()->{
            for(int i = 0; i < 5000; i++){
                counter501.increase();
            }
        });
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(" count = " + Counter501.count);

    }
}
class Counter501 {
    public static int count = 0;
    public synchronized void increase() {
        increase1();
    }
    private synchronized void increase1() {
        increase2();
    }
    private void increase2() {
        synchronized (this){
            count++;
        }
    }
}
